<template>
  <div style="width: 70%">
      <el-form ref="form" :model="form" label-width="80px" :rules="rules">
        <el-form-item label="用户名">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item label="登录名">
          <el-input v-model="form.loginName"></el-input>
        </el-form-item>
        <el-form-item label="性  别">
          <el-radio-group v-model="form.sex">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="邮  箱">
          <el-input v-model="form.email"></el-input>
        </el-form-item>


        <el-form-item label="密码" prop="passWord">
          <el-input type="password" v-model="form.passWord" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input type="password" v-model="form.checkPass" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="toPre">上一步</el-button>
          <el-button @click="toNext('form')" type="primary">下一步</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
        name: "register-info",
        data(){
          var validatePass = (rule, value, callback) => {
            if (value === '') {
              callback(new Error('请输入密码'));
            } else {
              if (this.form.checkPass !== '') {
                this.$refs.form.validateField('checkPass');
              }
              callback();
            }
          };
          var validatePass2 = (rule, value, callback) => {
            if (value === '') {
              callback(new Error('请再次输入密码'));
            } else if (value !== this.form.passWord) {
              callback(new Error('两次输入密码不一致!'));
            } else {
              callback();
            }
          };
          return{
            form:{
              loginName:"",
              userName:"",
              tel:"",
              email:"",
              sex:"",
              passWord:"",
              checkPass:""
            },
            rules: {
              password: [
                { validator: validatePass, trigger: 'blur' }
              ],
              checkPass: [
                { validator: validatePass2, trigger: 'blur' }
              ]
            }
          }
        },
        methods:{
          toNext(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                //注册信息
                this.form.tel=this.$store.state.tel;
                /* console.log("表单对象"+JSON.stringify(this.$data.form))
                 console.log("注册地址"+this.$gloableData.serverPath+"user/userReg/toRegister");*/
                this.$axios.post(this.$gloableData.serverPath+"user/userReg/toRegister",this.$data.form).then((response)=>{
                  this.$store.state.registerInfo=this.form
                  this.$emit("TT");


                }).catch((error)=>{
                  alert("注册失败，注意填写正确的信息")
                });

              } else {
                console.log('error!!');
                return false;
              }
            });


          },
          toPre(){
            this.$emit("PP")
          }
        }
    }
</script>

<style scoped>

</style>
